package com.duan.laugh.common.core.exception;

import com.duan.laugh.common.core.constants.CoreConstants;
import lombok.NoArgsConstructor;

/**
 * runtime异常
 * <p>
 * 所有异常继承次异常
 * @author duanjw
 */
@NoArgsConstructor
public class BaseRuntimeException extends RuntimeException {

    /**
     * 异常返回的错误码
     */
    public static Integer RUNTIME_EXCEPTION_CODE = -1;

    public BaseRuntimeException(String message) {
        super(message);
    }

    /**
     * 异常，只有错误码
     *
     * @param code
     */
    public BaseRuntimeException(Integer code) {
        super(code + CoreConstants.CODE_MESSAGE_SPLIT);
    }

    /**
     * 异常，有错误码和消息
     *
     * @param code
     */
    public BaseRuntimeException(Integer code, String message) {
        super(code + CoreConstants.CODE_MESSAGE_SPLIT + message);
    }

    public BaseRuntimeException(Throwable cause) {
        super(cause);
    }

    public BaseRuntimeException(String message, Throwable cause) {
        super(message, cause);
    }

    public BaseRuntimeException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
        super(message, cause, enableSuppression, writableStackTrace);
    }

    /**
     * 异常，错误对象
     *
     * @param codeMessage
     */
    public BaseRuntimeException(ICodeMessage codeMessage) {
        super(codeMessage.getCode() + CoreConstants.CODE_MESSAGE_SPLIT + codeMessage.getMsg());
    }

    /**
     * 获取错误码
     *
     * @return
     */
    public Integer getCode() {
        return RUNTIME_EXCEPTION_CODE;
    }
}
